using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace LigerUi.MVC.DataModel.EntityClasses.Models.Mapping
{
    public class CF_DepartmentMap : EntityTypeConfiguration<CF_Department>
    {
        public CF_DepartmentMap()
        {
            // Primary Key
            this.HasKey(t => t.DepartmentID);

            // Properties
            this.Property(t => t.DepartmentNo)
                .IsRequired()
                .HasMaxLength(50);

            this.Property(t => t.DepartmentName)
                .IsRequired()
                .HasMaxLength(100);

            this.Property(t => t.Remark)
                .HasMaxLength(4000);

            this.Property(t => t.RecordStatus)
                .IsRequired()
                .HasMaxLength(20);

            this.Property(t => t.FullPath)
                .HasMaxLength(2000);

            this.Property(t => t.Guid)
                .IsRequired()
                .HasMaxLength(50);

            // Table & Column Mappings
            this.ToTable("CF_Department");
            this.Property(t => t.DepartmentID).HasColumnName("DepartmentID");
            this.Property(t => t.DepartmentNo).HasColumnName("DepartmentNo");
            this.Property(t => t.DepartmentName).HasColumnName("DepartmentName");
            this.Property(t => t.ParentID).HasColumnName("ParentID");
            this.Property(t => t.CompanyID).HasColumnName("CompanyID");
            this.Property(t => t.Remark).HasColumnName("Remark");
            this.Property(t => t.RecordStatus).HasColumnName("RecordStatus");
            this.Property(t => t.FullPath).HasColumnName("FullPath");
            this.Property(t => t.CreateUserID).HasColumnName("CreateUserID");
            this.Property(t => t.CreateDate).HasColumnName("CreateDate");
            this.Property(t => t.ModifyUserID).HasColumnName("ModifyUserID");
            this.Property(t => t.ModifyDate).HasColumnName("ModifyDate");
            this.Property(t => t.Guid).HasColumnName("Guid");

            // Relationships
            this.HasRequired(t => t.CF_Company)
                .WithMany(t => t.CF_Department)
                .HasForeignKey(d => d.CompanyID);
            this.HasOptional(t => t.CF_Department2)
                .WithMany(t => t.CF_Department1)
                .HasForeignKey(d => d.ParentID);

        }
    }
}
